import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:inmotion_pro/l10n/local.dart';
import '../../../../service/global_service.dart';
import '../widgets/iq_output_max_view.dart';
import 'tech_form_base.dart';

class IqForm extends StatelessWidget {
  final RxDouble iq;
  final RxDouble maxIq;
  final double height;
  final Function()? onClear;
  const IqForm(
      {required this.iq,
      required this.maxIq,
      required this.height,
      this.onClear,
      super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      final vehicleType = GlobalService.to.currentVehicleType;
      final low = vehicleType.getOutputVectorVoltagePercentageLowThreshold();
      final high = vehicleType.getOutputVectorVoltagePercentageHighThreshold();
      return TechFormBase(
        value: iq.value,
        height: height,
        unit: 'A',
        valueLabel: local.current_iq,
        icon: Icons.bolt,
        colorBuilder: (rate) {
          if (rate < low) return Colors.blueAccent;
          if (rate > high) return Colors.redAccent;
          return Colors.greenAccent;
        },
        statusBuilder: (rate) {
          return null;
        },
        statusIconBuilder: (rate) {
          return null;
        },
        // 显示最大值
        externalWidget: IQOutputMaxView(
          maxIq,
          onClear: onClear,
          unit: 'A',
        ),
      );
    });
  }
}
